import { Component, OnInit, HostBinding, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { MatDialog } from '@angular/material'

import {NewTaskComponent} from "../new-task/new-task.component";
import {CopyTaskComponent} from "../copy-task/copy-task.component";
import {ConfirmDialogComponent} from "../../shared/confirm-dialog/confirm-dialog.component";
import {NewTaskListComponent} from "../new-task-list/new-task-list.component";
import {slideToRight} from "../../anims/router.anim";

@Component({
  selector: 'app-task-home',
  templateUrl: './task-home.component.html',
  styleUrls: ['./task-home.component.scss'],
  animations: [slideToRight],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class TaskHomeComponent implements OnInit {
  lists = [
    {
      id: 1,
      name: '待办',
      tasks: [
        {
          id: 1,
          desc: '任务一:去星巴克买咖啡',
          completed : true,
          priority: 3,
          owner: {
            id: 1,
            name: '张三',
            avatar: 'avatars:svg-11',
          },
          dueDate: new Date(),
        },
        {
          id: 2,
          desc: '任务二:完成ppt大多数的的士速递',
          completed: false,
          priority: 2,
          owner: {
            id: 1,
            name: '李四',
            avatar: 'avatars:svg-12',
          },
          dueDate: new Date(),
        }
      ]
    },
    {
      id: 1,
      name: '进行中',
      tasks: [
        {
          id: 1,
          desc: '任务一:去看电影',
          completed: true,
          priority: 1,
          owner: {
            id: 1,
            name: '王五',
            avatar: 'avatars:svg-9',
          },
          dueDate: new Date(),
          reminder: new Date(),
        },
        {
          id: 2,
          desc: '任务二:看女朋友',
          completed: false,
          priority: 2,
          owner: {
            id: 1,
            name: '李四',
            avatar: 'avatars:svg-10',
          },
          dueDate: new Date(),
        }
      ]
    }
  ]

  constructor(private dialog: MatDialog, private cd: ChangeDetectorRef) { }
  @HostBinding('@routerAnim')

  ngOnInit() {
  }
  // 打开新建任务弹框
  lanuchNewTaskDialog() {
    this.dialog.open(NewTaskComponent, {data: {title: '新建任务'}});
  }
  // 修改本列表所有内容弹框
  lanuchCopyTaskDialog() {
    this.dialog.open(CopyTaskComponent, {data: {lists: this.lists}});
  }
  // 修改任务弹框
  lanuchUpdateTaskDialog(task) {
    this.dialog.open(NewTaskComponent, {data: {title: '修改任务', task}})
  }
  // 打开删除
  lanuchConfirmDialog() {
    this.dialog.open(ConfirmDialogComponent, {data: {title: '删除任务', content: '您确定要删除该任务吗?'}})
  }
  // 打开修改列表名称
  lanuchEditListDialog() {
    this.dialog.open(NewTaskListComponent, {data: {title: '修改列表名称'}})
  }
  // 新建列表
  lanuchNewListDialog() {
    this.dialog.open(NewTaskListComponent, {data: {title: '新建列表'}})
  }
  // 新建快速新建任务
  handleQuickTask(quickData: string) {
    // console.log(quickData)
  }
}
